/*
* SMILParser
*
* Version 1.0
*
* Programmers: Jesse Louderback, Noah Pham, Chad Carpenter, and Marc Hindman
*/
package Message;

import android.graphics.Color;

public class SMILText {
	protected float startTime = 0.0f;
	protected float endTime = 0.0f;
	protected String text = "";
	protected int xLoc = 0;
	protected int yLoc = 0;
	protected String region;
	protected float textSize = 20;
	protected int color = Color.WHITE;

	public SMILText(SMILObject ob) {
		getTextData(ob.data);
		startTime = ob.startTime;
		endTime = ob.endTime + ob.startTime;
		region = ob.region;
	}

	public void getTextData(String data) {
		try {
			String holder[];
			holder = data.split(",", 3);
			if (holder.length == 3) {
				for (String h : holder) {
					
					// text color
					if (h.contains("textColor:")) {
						color = Integer.parseInt(h.substring(10, h.length()));
						
					// text size
					} else if (h.contains("textSize:")) {
						textSize = Float.parseFloat(h.substring(9, h.length()));
						
					// data
					} else if (h.contains("data:")) {
						text = h.substring(5, h.length());
					}
				}
			} else {
				text = data;
			}
		} catch (Exception e) {
			text = data;
		}
	}

	public float getStartTime() {
		return startTime;
	}

	public float getEndTime() {
		return endTime;
	}

	public String getText() {
		return text;
	}

	public int getxLoc() {
		return xLoc;
	}

	public void setxLoc(int xLoc) {
		this.xLoc = xLoc;
	}

	public int getyLoc() {
		return yLoc;
	}

	public void setyLoc(int yLoc) {
		this.yLoc = yLoc;
	}

	public void setStartTime(float startTime) {
		this.startTime = startTime;
	}

	public void setEndTime(float endTime) {
		this.endTime = endTime;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public void incTextSize() {
		textSize += 1;
	}

	public void decTextSize() {
		textSize -= 1;
	}

	public float getTextSize() {
		return textSize;
	}

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public void setTextSize(float textSize) {
		this.textSize = textSize;
	}

	@Override
	public String toString() {
		return "<text region=\"" + region + "\" src=\"textColor:" + color
				+ ",textSize:" + textSize + ",data:" + text + "\" begin=\""
				+ startTime + "\" dur=\"" + endTime + "\" />";
	}
}
